local game = { running = true, dino = { x = 10, y = 40, width = 10, height = 10, jumping = false, velocity = 0 }, obstacles = {}, score = 0, gravity = 1, jumpStrength = -7, obstacleSpeed = 3, spawnTimer = 0, spawnInterval = system.random(1, 1000), highscore = 0 } local function drawDino() display.drawRectangle(game.dino.x, game.dino.x + game.dino.width, game.dino.y, game.dino.y + game.dino.height, 1, 1) end local function drawObstacles() for _, obstacle in ipairs(game.obstacles) do display.drawRectangle(obstacle.x, obstacle.x + obstacle.width, obstacle.y, obstacle.y + obstacle.height, 1, 1) end end local function updateDino() if game.dino.jumping then game.dino.velocity = game.dino.velocity + game.gravity game.dino.y = game.dino.y + game.dino.velocity if game.dino.y >= 40 then game.dino.y = 40 game.dino.jumping = false game.dino.velocity = 0 end end end local function updateObstacles() for i = #game.obstacles, 1, -1 do local obstacle = game.obstacles[i] obstacle.x = obstacle.x - game.obstacleSpeed if obstacle.x + obstacle.width < 0 then table.remove(game.obstacles, i) game.score = game.score + 1 end end end local function spawnObstacle() local obstacle = { x = 128, y = 45, width = 5, height = 5 } table.insert(game.obstacles, obstacle) game.spawnInterval = system.random(2000, 4000) end local function checkCollision() for _, obstacle in ipairs(game.obstacles) do if game.dino.x < obstacle.x + obstacle.width and game.dino.x + game.dino.width > obstacle.x and game.dino.y < obstacle.y + obstacle.height and game.dino.y + game.dino.height > obstacle.y then game.running = false end end end function main() display.clear() display.statusBar(1) local loadthisshit = system.loadData() if loadthisshit ~= "" and loadthisshit ~= nil then local success, loadedtable = pcall(json.parse, loadthisshit) if success and loadedtable and tonumber(loadedtable.highscore) then game.highscore = tonumber(loadedtable.highscore) else game.highscore = 0 end else game.highscore = 0 end while true do if (input.aBtn() or input.bBtn() or input.cBtn()) and not game.dino.jumping then game.dino.jumping = true game.dino.velocity = game.jumpStrength end if input.dBtn() then break end updateDino() updateObstacles() checkCollision() if game.running == false then if game.highscore < game.score then game.highscore = tonumber(game.score) end game.score = 0 game.running = true end game.spawnTimer = game.spawnTimer + 100 if game.spawnTimer >= game.spawnInterval then spawnObstacle() game.spawnTimer = 0 end display.clear() drawDino() drawObstacles() display.drawLine(0,50,128,50,1) display.printText("" .. game.score, 0, 10, 2) display.printText("Highscore: " .. game.highscore, 0, 30, 1) display.display() --system.delay(50) end display.clear() display.printCenterText("Bye!", 20) display.printCenterText("Score: " .. game.score, 30) display.printCenterText("Highscore: " .. game.highscore, 40) if game.highscore < game.score then game.highscore = tonumber(game.score) end local savethisshit = { highscore = game.highscore } system.saveData(json.stringify(savethisshit)) display.display() system.delay(1500) end